package com.baicun.wish.controller;

import cn.hutool.core.map.MapUtil;
import cn.hutool.json.JSONObject;
import com.baicun.wish.entity.CollegeBasic;
import com.baicun.wish.entity.dto.Result;
import com.baicun.wish.service.CollegeBasicService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author baicun
 * @since 2020-09-07
 */
@RestController
@RequestMapping("/college-basic")
public class CollegeBasicController {

    @Autowired
    private CollegeBasicService collegeBasicService;

    /**
     * 根据collegeName查询college-basic表中大学数据
     * create index index_college_name on college_basic(college_name);
     * @return Result
     */
    @PostMapping("/getCollegeBasicByCollegeName")
    public Result getCollegeBasicByCollegeName(@RequestBody JSONObject jsonObject){
        String collegeName = jsonObject.getStr("collegeName");
        System.out.println(collegeName);
        CollegeBasic collegeBasic = collegeBasicService.getOne(new QueryWrapper<CollegeBasic>().eq("college_name", collegeName));
        //处理图片
        String[] pictrues = null;
        if (collegeBasic.getPictures() != null){
            pictrues = collegeBasic.getPictures().split("\\|");
        }
        return Result.success(MapUtil.builder().put("collegeBasic", collegeBasic).put("pictrues",pictrues).map());
    }

}
